<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>固定导航栏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        img{
            vertical-align: top;
        }
        div {
            text-align: center;
        }
        div.top{
            height: 168px;
        }
        div.main{
            margin-top: 10px;
        }
    </style>
    <script src="../lib/jquery-3.4.1.js"></script>
    <script>
        $(function(){
            var tH = $(".top").height();
            console.log(tH);
            $(window).scroll(function(){
                var sh = $(document).scrollTop();
                console.log(sh);
                if(sh>=tH){
                    // 导航固定定位
                    $(".nav").css({
                        position:'fixed',
                        top:0,
                        left:'50px'
                    });

                    $(".main").css({
                        marginTop:10+$(".nav").height()+"px"
                    })
                }else {
                    $(".nav").css({
                        position:'static',
                        top:0,
                        left:'50px'
                    });
                    $(".main").css({
                        marginTop:10+"px"
                    })
                }
            });
        });
    </script>
</head>
<body>
    <div class="top">
        <img src="./imgs/top.png" alt="">
    </div>
    <div class="nav">
        <img src="./imgs/nav.png" alt="">
    </div>
    <div class="main">
        <img src="./imgs/main.png" alt="">
    </div>
</body>
</html>